package response

import (
	"github.com/gin-gonic/gin"
)

type ResponseObject struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (o ResponseObject) ToJSON(c *gin.Context) {
	c.JSON(200, &o)
}

func Success(data interface{}) *ResponseObject {
	return &ResponseObject{
		Code: 200,
		Msg:  "success",
		Data: data,
	}
}

func Error(code int, msg string) *ResponseObject {
	return &ResponseObject{
		Code: code,
		Msg:  msg,
		Data: nil,
	}
}
